<template>
 <a-form :label-col="{ span: 4 }" :wrapper-col="{ span: 20 }" class="formMsg">
    <a-form-item label="消息">
     <a-textarea v-model:value="msg" placeholder="该消息会发送到所有端" :rows="4" @keydown.enter="sendmsg"/>
    </a-form-item>
    <a-form-item :wrapper-col="{ span: 14, offset: 4 }" style="text-align:center">
      <a-button type="primary" @click="sendmsg">发送</a-button>
    </a-form-item>
  </a-form>
</template>
<script>
import signalr  from "./signalr/chat";
export default {
  data() {
    return {
      msg:'',
    }
  },
  mounted() {
    this.initConnect()
    this.registMsg()
  },
  methods: {
    initConnect(){
      signalr.chart.getInstance();
    },
    registMsg(){
      signalr.chart.getInstance().on('ReceiveMessage',item=>{
        this.$message.success(item);
      })
    },
    sendmsg(){
      signalr.chart.getInstance().send('SendMessageAll',this.msg);
    }
  },
}
</script>
<style scoped>
.formMsg{
  position: absolute;
    left:50%;
    top:50%;
    transform: translate(-50%, -50%);
    width: 300px;
    height: 300px;
}
</style>
